public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().maxProfit(new int[]{7,1,5,3,6,4}));
    }
}


class Solution {
    public int maxProfit(int[] prices) {
        int curMin = prices[0];
        int maxPro = 0;
        for (int price : prices) {
            if (price < curMin) {
                curMin = price;
                continue;
            }
            maxPro = Math.max(price - curMin, maxPro);
        }
        return maxPro;
    }
}